package A1;

import java.util.ArrayList;



/**
 * Created by IntelliJ IDEA.
 * User: Ferdy
 * Date: 31 Mar 11
 * Time: 13:59:07
 * To change this template use File | Settings | File Templates.
 */
/**class to save all the data*/
public class Model {
    private int horLane = 0;
    private int verLane = 0;
    private double verCar = 0.0;
    private double horCar = 0.0;
    private char[][] cell;
    private int userRun=0;
    private int run=0;

    Grid gr=new Grid();
    Cars ca=new Cars();
    TrafficLight tl=new TrafficLight();

    ArrayList<Cars> hCarList=new ArrayList<Cars>();
    ArrayList<Cars> vCarList=new ArrayList<Cars>();

    /**get the horizontal lane*/
    public int getHorLane(){return horLane;}
    /**set the horizontal lane*/
    public void setHorLane(String horizontal){
        int a=Integer.parseInt(horizontal);
        horLane=a;
    }

    /**get the vertical lane*/
    public int getVerLane(){return verLane;}
    /**set the vertical lane*/
    public void setVerLane(String vertical){
        int b=Integer.parseInt(vertical);
        verLane=b;
    }

    /**get the probability for horizontal car*/
    public double getHorCar(){return horCar;}
    /**set the probability for horizontal car*/
    public void setHorCar(double hCar){
        horCar=hCar;
    }

    /**get the probability for vertical car*/
    public double getVerCar(){return verCar;}
    /**set the probability for vertical car*/
    public void setVerCar(double vCar){
           verCar=vCar;
    }

    /**set the cell*/
    public void setCell(){
        cell=gr.road(horLane,verLane);
    }

    /**get the number of user want to run*/
    public int getUserRun(){return userRun;}
    /**set the number of user want to run*/
    public void setUserRun(int u){
        userRun=u;
    }

    /**set the position of car and lane. Print grid*/
    public void setGrid(){
        for(int i=0;i<getUserRun();i++)
        {
            hCarList=ca.setHorCar(hCarList,getHorLane(),getHorCar(),run);
            vCarList=ca.setVerCar(vCarList,getVerLane(),getVerCar(),run);
            tl.trafficLight(run);
            cell=tl.trafficLightPos(tl.trafficLight,cell,getVerLane());

            for(int j=0;j<=run;j++) {
            cell=gr.gridHorCar(cell,j,hCarList,tl.trafficLight);
            cell=gr.gridVerCar(cell,j,vCarList,tl.trafficLight);
            }

            gr.printGrid(cell);
            run++;
        }
    }

}
